﻿namespace MsdnWeb

open SignalR
open Newtonsoft.Json
open System.Threading.Tasks
open MPI

module SignalRConnection =
    

    type MySignalRConnection() =
            inherit PersistentConnection()

            let worker = 
                let a = MPI.agent()
                a.Start()
                a

            override self.OnConnectedAsync(req,connid) =
                //brodacast the connected value back to the client 
                //self.Connection.Broadcast() |> ignore 
                base.OnConnectedAsync(req,connid)

            override self.OnDisconnectAsync(connid) = 
                //brodacast the disconnected value back to the client 
                //self.Connection.Broadcast() |> ignore 
                base.OnDisconnectAsync(connid)

            override self.OnErrorAsync(ex) = 
                // do something with the exception
                base.OnErrorAsync(ex)


            override self.OnReceivedAsync(req,connid,data) = 
                worker.Post(Req(data,self)) //posting a message to the Agent
                base.OnReceivedAsync(req,connid,data)
                //self.Connection.Broadcast(data) //simple echo test
                    